package com.ruoyi.arrangement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.arrangement.domain.TbDateArrangement;
import com.ruoyi.arrangement.service.ITbDateArrangementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.user.domain.TbUser;
import com.ruoyi.matchmaker.domain.TbMatchmaker;
import com.ruoyi.user.mapper.TbUserMapper;
import com.ruoyi.request.domain.TbMatchmakingRequest;
import com.ruoyi.request.mapper.TbMatchmakingRequestMapper;

/**
 * 约会安排Controller
 * 
 * @author ruoyi
 * @date 2025-08-01
 */
@RestController
@RequestMapping("/arrangement/arrangement")
public class TbDateArrangementController extends BaseController
{
    @Autowired
    private ITbDateArrangementService tbDateArrangementService;

    @Autowired
    private TbUserMapper tbUserMapper;

    @Autowired
    private TbMatchmakingRequestMapper tbMatchmakingRequestMapper;

    /**
     * 查询约会安排列表
     */
    @PreAuthorize("@ss.hasPermi('arrangement:arrangement:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbDateArrangement tbDateArrangement)
    {
        startPage();
        List<TbDateArrangement> list = tbDateArrangementService.selectTbDateArrangementList(tbDateArrangement);
        return getDataTable(list);
    }

    /**
     * 导出约会安排列表
     */
    @PreAuthorize("@ss.hasPermi('arrangement:arrangement:export')")
    @Log(title = "约会安排", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDateArrangement tbDateArrangement)
    {
        List<TbDateArrangement> list = tbDateArrangementService.selectTbDateArrangementList(tbDateArrangement);
        ExcelUtil<TbDateArrangement> util = new ExcelUtil<TbDateArrangement>(TbDateArrangement.class);
        util.exportExcel(response, list, "约会安排数据");
    }





    /**
     * 删除约会安排
     */
    @PreAuthorize("@ss.hasPermi('arrangement:arrangement:remove')")
    @Log(title = "约会安排", businessType = BusinessType.DELETE)
	@DeleteMapping("/{arrangementIds}")
    public AjaxResult remove(@PathVariable Long[] arrangementIds)
    {
        return toAjax(tbDateArrangementService.deleteTbDateArrangementByArrangementIds(arrangementIds));
    }

    /**
     * 根据用户ID获取用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('arrangement:arrangement:query')")
    @GetMapping("/user/{userId}")
    public AjaxResult getUserInfo(@PathVariable("userId") Long userId)
    {
        TbUser user = tbUserMapper.selectTbUserByUserId(userId);
        return success(user);
    }

    /**
     * 根据红娘ID获取红娘详细信息
     */
    @PreAuthorize("@ss.hasPermi('arrangement:arrangement:query')")
    @GetMapping("/matchmaker/{matchmakerId}")
    public AjaxResult getMatchmakerInfo(@PathVariable("matchmakerId") Long matchmakerId)
    {
        TbMatchmaker matchmaker = tbUserMapper.selectTbMatchmakerByMatchmakerId(matchmakerId);
        return success(matchmaker);
    }

    /**
     * 根据申请ID获取牵线申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('arrangement:arrangement:query')")
    @GetMapping("/request/{requestId}")
    public AjaxResult getRequestInfo(@PathVariable("requestId") Long requestId)
    {
        TbMatchmakingRequest request = tbMatchmakingRequestMapper.selectTbMatchmakingRequestByRequestId(requestId);
        return success(request);
    }
}
